package com.jic.market.impl;

import com.google.common.base.Joiner;
import com.jic.market.common.base.MarketBaseService;
import com.jic.market.entity.PromotionEntity;
import com.jic.market.mapper.PromotionExchangeMapper;
import com.jic.market.request.PromotionRequest;
import com.jic.market.response.PromotionResponse;
import com.jic.market.service.JicMarketPromotionExchangeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author mzp
 * @version 1.0
 * @description
 * @date 2020/3/13 14:47
 */
@Slf4j
@Service
public class JicMarketPromotionExchangeServiceImpl extends MarketBaseService implements JicMarketPromotionExchangeService {

    @Resource
    PromotionExchangeMapper promotionExchangeMapper;
    /**
     * 添加换购促销活动信息
     * @param request
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public PromotionResponse savejicMarketPromotionExchangeService(PromotionRequest request) {
        PromotionResponse response = new PromotionResponse();
        PromotionEntity promotionEntity = new PromotionEntity();
        promotionEntity.setProPlatform("2");
        promotionEntity.setProMemberLevel("3");
        promotionEntity.setProMemberType("0");
        promotionEntity.setChannelCodes(request.getChannelCodes());
        promotionEntity.setProUserType(Joiner.on("|").join(request.getProUserType()));
        BeanUtils.copyProperties(request, promotionEntity);


        promotionExchangeMapper.insertPromotionExchange(promotionEntity);
        return response;
    }
    public static void main(String[] args) {
        Date time =new Date("Tue Mar 26 00:00:00 CST 2019");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
        String timeFormat = sdf.format(time);
        log.info(timeFormat);
    }
}

